<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="../../assets/css/maincss.css" rel="stylesheet" />
<link href="../../assets/css/but.css" rel="stylesheet" />
</head>
<body>
	<h3>类别管理</h3>
	<a href="searchCategorys.jsp">查询类别</a>
	<table border="1px" cellspacing="0" height="280px" width="900px" align="center" style="text-align: center;" rules="rows" frame="void">
		<tr>
			<td colspan="4" style="text-align: right;">
				<button onclick="addCategoryBut()" class="but green">增 加</button>
			</td>
		</tr>
		<tr>
			<td>类别id</td>
			<td>类别名称</td>
			<td>类别简介</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${page.list}" var="cate">
			<tr>
				<td>${cate.categoryId}</td>
				<td>${cate.categoryName}</td>
				<td>${cate.categoryDesc}</td>
				<td>
					<button onclick="editCategoryById(${cate.categoryId})" class="but green">修 改</button>
					&nbsp;
					<button onclick="return delCategoryById(${cate.categoryId})" class="but red">删 除</button>
				</td>
			</tr>
		</c:forEach>
		
		<tr align="center">
			<td colspan="4">
				
				<c:if test="${page.currentPage != 1}">
					<a href="CategoryServlet?op=showCategoryByPage&currentPage=${page.upPage()}">[上一页]</a>
				</c:if>
				
				&nbsp;&nbsp;&nbsp;&nbsp;
				当前第${page.currentPage}页
				&nbsp;&nbsp;
				共${page.total}条数据
				&nbsp;&nbsp;
				共${page.totalPages()}页
				&nbsp;&nbsp;&nbsp;&nbsp;
				<c:if test="${page.currentPage != page.totalPages()}">
					<a href="CategoryServlet?op=showCategoryByPage&currentPage=${page.nextPage()}">[下一页]</a>
				</c:if>
			</td>
		</tr>
	</table>
	

</body>
<script type="text/javascript">
	
	// 修改
	function editCategoryById(id){
		location.href = 'CategoryServlet?op=readyEditCategoryById&id='+id;
	}
	
	// 删除
	function delCategoryById(id){
		var msg = "确定删除该条数据?";
		if(confirm(msg) == true){
			location.href='CategoryServlet?op=removeCategoryById&id='+id;
			return true;
		} else {
			return false;	
		}
	}
	
	// 增加
	function addCategoryBut(){
		location.href='addCategory.jsp';
	}



</script>
</html>